

project(qbcalculator)

find_package(Qt5 COMPONENTS Core REQUIRED)

file(GLOB_RECURSE  SRCS CONFIGURE_DEPENDS ./*.cpp)
source_group_by_dir(SRCS)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/)

add_library(${PROJECT_NAME} SHARED
     ${SRCS}
)


if(WINDOWS)
    target_compile_options(${PROJECT_NAME} PRIVATE -DSSCALCULATOR_EXPORTS /wd4251)
elseif (LINUX)
    target_compile_options(${PROJECT_NAME} PRIVATE -DSSCALCULATOR_EXPORTS -fpermissive -fPIC)
elseif (MACOS)
    target_compile_options(${PROJECT_NAME} PRIVATE -DSSCALCULATOR_EXPORTS -fpermissive -fPIC) 
endif()

target_link_libraries(${PROJECT_NAME} PRIVATE Qt::Core core qbprotocol uam bondlib msgcenter)

if(WINDOWS)
    target_link_libraries(${PROJECT_NAME} PRIVATE
    debug ${CMAKE_CURRENT_SOURCE_DIR}/lib/debug/SSCalculatorD.lib
    optimized ${CMAKE_CURRENT_SOURCE_DIR}/lib/release/SSCalculator.lib)
    target_link_libraries(${PROJECT_NAME} PRIVATE
    debug ${CMAKE_CURRENT_SOURCE_DIR}/lib/debug/QuantLib--mt-gd.lib
    optimized ${CMAKE_CURRENT_SOURCE_DIR}/lib/release/QuantLib--mt.lib)
    target_link_libraries(${PROJECT_NAME} PRIVATE
    debug ${CMAKE_CURRENT_SOURCE_DIR}/lib/debug/BondYieldCurveD.lib
    optimized ${CMAKE_CURRENT_SOURCE_DIR}/lib/release/BondYieldCurve.lib)
    target_link_libraries(${PROJECT_NAME} PRIVATE
    debug ${CMAKE_CURRENT_SOURCE_DIR}/lib/debug/libboost_regex-vc142-mt-gd-x32-1_81.lib
    optimized ${CMAKE_CURRENT_SOURCE_DIR}/lib/release/libboost_regex-vc142-mt-gd-x32-1_81.lib)
elseif(MACOS)
    target_link_libraries(${PROJECT_NAME} PRIVATE
    debug ${CMAKE_CURRENT_SOURCE_DIR}/lib/macos/${CMAKE_OSX_ARCHITECTURES}/libSSCalculator.a
    optimized ${CMAKE_CURRENT_SOURCE_DIR}/lib/macos/${CMAKE_OSX_ARCHITECTURES}/libSSCalculator.a)
    # find_package(PkgConfig REQUIRED)
    # pkg_check_modules(QuantLib REQUIRED IMPORTED_TARGET QuantLib)
    # target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::QuantLib)
    target_link_libraries(${PROJECT_NAME} PRIVATE
    debug ${CMAKE_CURRENT_SOURCE_DIR}/lib/macos/${CMAKE_OSX_ARCHITECTURES}/libQuantLib.a
    optimized ${CMAKE_CURRENT_SOURCE_DIR}/lib/macos/${CMAKE_OSX_ARCHITECTURES}/libQuantLib.a)
    target_link_libraries(${PROJECT_NAME} PRIVATE
    debug ${CMAKE_CURRENT_SOURCE_DIR}/lib/macos/${CMAKE_OSX_ARCHITECTURES}/libBondYieldCurve.a
    optimized ${CMAKE_CURRENT_SOURCE_DIR}/lib/macos/${CMAKE_OSX_ARCHITECTURES}/libBondYieldCurve.a)
    # set(Boost_USE_STATIC_LIBS ON)
    # find_package(Boost REQUIRED COMPONENTS regex)
    # target_link_libraries(${PROJECT_NAME} Boost::regex)
    # target_link_libraries(${PROJECT_NAME} PRIVATE
    # debug ${CMAKE_CURRENT_SOURCE_DIR}/lib/macos/libboost_regex.a
    # optimized ${CMAKE_CURRENT_SOURCE_DIR}/lib/macos/libboost_regex.a)
else()
    target_link_libraries(${PROJECT_NAME} PRIVATE
    debug ${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/libSSCalculatorD.a
    optimized ${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/libSSCalculator.a)
    target_link_libraries(${PROJECT_NAME} PRIVATE
    debug ${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/libQuantLibD.a
    optimized ${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/libQuantLib.a)
    target_link_libraries(${PROJECT_NAME} PRIVATE
    debug ${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/libBondYieldCurveD.a
    optimized ${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/libBondYieldCurve.a)
    target_link_libraries(${PROJECT_NAME} PRIVATE
    debug ${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/libboost_regex.a
    optimized ${CMAKE_CURRENT_SOURCE_DIR}/lib/linux/libboost_regex.a)
endif()
